<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>修改房间信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/js/cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="roomNumber" class="layui-form-label">
                房间门号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="roomNumber" name="roomNumber" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="roomType" class="layui-form-label">
                房间类型
            </label>
            <div class="layui-input-inline">
                <input type="text" id="roomType" name="roomType" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
                房间价格
            </label>
            <div class="layui-input-inline">
                <input type="text" id="price" name="price" required="" lay-verify="number"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="curStatus" class="layui-form-label">
                房间状态
            </label>
            <div class="layui-input-inline">
                <select name="curStatus" id="curStatus" class="layui-select-group">
                    <option name="status" value="空闲">空闲</option>
                    <option name="status" value="入住">入住</option>
                    <option name="status" value="维修">维修</option>
                    <option name="status" value="废弃">废弃</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="roomTel" class="layui-form-label">
                客房电话
            </label>
            <div class="layui-input-inline">
                <input type="tel" id="roomTel" name="roomTel" required="" lay-verify="roomTel"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button class="layui-btn" lay-filter="edit" lay-submit="">
                提交修改
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        var $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
        //自定义验证规则
        form.verify({
            //验证固定号码是否有误
            roomTel: [/\d{3,4}[-]\d{7}/, "房间固定号码格式有误"]
        });
        // 获取父窗口中存储的下拉框选中的值
        var select = parent.$("#selectValue").val();
        // console.log(select);
        // console.log($("#curStatus option[value = '入住']"));
        $("#curStatus option[value = "+select+"]").prop("selected",true);
        //渲染表单中的下拉框！！
        form.render('select');
        //监听提交
        form.on('submit(edit)', function (data) {
            //发异步，把数据提交给后台
            //获取到表单数据
            //console.log(data.field);
            //data.field为表单中的数据！
            $.post("", data.field, function (data2, status) {
                if (status == "success") {
                    layer.alert("修改成功", {icon: 6}, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                }
                else{
                    // console.log("shibai");
                    layer.alert("修改失败", {icon: 5})
                }
            });
            return false;



        });


    });
</script>

</body>

</html>